#include "SettingWidget.h"

SettingWidget::SettingWidget(QWidget *parent)
    : QWidget{parent}
{
    setWindowTitle("设置");
    setFixedSize(570,450);
    this->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
    this->setStyleSheet("QListWidget {background-color: transparent;border: none;}QListWidget::item {height: 30px;padding-left: 0px;}QListWidget::item:selected { background-color: transparent;padding-left: 0px;color: #007aff;outline: none;}");
    initWidget();
    init();
}

void SettingWidget::init()
{
    m_MainLayout = new QHBoxLayout(this);

    // 左侧导航栏（QListWidget 或 QVBoxLayout + QPushButton）
    m_NavList = new QListWidget();
    m_NavList->addItem("文件");
    m_NavList->addItem("客户端");
    m_NavList->setMaximumWidth(70);

    // 右侧设置页面（QStackedWidget）
    m_StackedWidget = new QStackedWidget();
    m_StackedWidget->addWidget(m_ClientSetting);
    m_StackedWidget->addWidget(m_FileSetting);

    m_NavList->setCurrentRow(0);

    connect(m_NavList, &QListWidget::currentRowChanged, m_StackedWidget, &QStackedWidget::setCurrentIndex);

    m_MainLayout->addWidget(m_NavList);
    m_MainLayout->addWidget(m_StackedWidget);
}

void SettingWidget::initWidget()
{
    m_ClientSetting = new QWidget(this);
    QLabel* label = new QLabel("新备注",m_ClientSetting);
    label->move(30,75);
    QLineEdit* linet = new QLineEdit(m_ClientSetting);
    linet->resize(300,30);
    linet->move(90,70);

    m_FileSetting = new QWidget(this);
    QLabel* fileLabel = new QLabel("文件路径",m_FileSetting);
    fileLabel->move(30,75);
    QLineEdit* fileLient = new QLineEdit(m_FileSetting);
    fileLient->setText(QDir::homePath());
    fileLient->resize(300,30);
    fileLient->move(100,70);
    QPushButton* saveFilePath = new QPushButton("确定",m_FileSetting);
    saveFilePath->move(180,120);
    QPushButton* FilePath = new QPushButton("浏览",m_FileSetting);
    FilePath->move(400,70);

    connect(saveFilePath,&QPushButton::clicked,this,[=](){
        emit signal_UpdateFileSavePath(fileLient->text());
    });

    connect(FilePath,&QPushButton::clicked,this,[=](){
        QString dir = QFileDialog::getExistingDirectory(this,
                    tr("选择文件夹"),
                    QDir::homePath(),
                    QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
        if (!dir.isEmpty()) {
            fileLient->setText(dir);
        }
    });
}
